/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Allocation")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Allocation.findAll", query = "SELECT a FROM Allocation a"),
    @NamedQuery(name = "Allocation.findByAllocationID", query = "SELECT a FROM Allocation a WHERE a.allocationID = :allocationID"),
    @NamedQuery(name = "Allocation.findByAllocationCustGroupID", query = "SELECT a FROM Allocation a WHERE a.allocationCustGroupID = :allocationCustGroupID"),
    @NamedQuery(name = "Allocation.findByAllocationStartDate", query = "SELECT a FROM Allocation a WHERE a.allocationStartDate = :allocationStartDate"),
    @NamedQuery(name = "Allocation.findByAllocationModDate", query = "SELECT a FROM Allocation a WHERE a.allocationModDate = :allocationModDate"),
    @NamedQuery(name = "Allocation.findByAllocationDueDate", query = "SELECT a FROM Allocation a WHERE a.allocationDueDate = :allocationDueDate"),
    @NamedQuery(name = "Allocation.findByAllocationFilled", query = "SELECT a FROM Allocation a WHERE a.allocationFilled = :allocationFilled"),
    @NamedQuery(name = "Allocation.findOpenAllocations", query = "SELECT a FROM Allocation a WHERE a.allocationFilled = false ORDER BY a.allocationDueDate ASC")})
public class Allocation implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "AllocationID")
    private Integer allocationID;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AllocationStartDate")
    @Temporal(TemporalType.DATE)
    private Date allocationStartDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AllocationModDate")
    @Temporal(TemporalType.DATE)
    private Date allocationModDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AllocationDueDate")
    @Temporal(TemporalType.DATE)
    private Date allocationDueDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AllocationFilled")
    private boolean allocationFilled;
    @Basic(optional = false)
    @NotNull
    @Column(name = "templateID")
    private int templateID;
    @JoinColumn(name = "AllocationCustGroupID", referencedColumnName = "CustomerGroupID")
    @ManyToOne(optional = false)
    private CustomerGroup allocationCustGroupID;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTAL",
        joinColumns={ @JoinColumn(name="AllocationID", referencedColumnName="AllocationID")},
        inverseJoinColumns={ @JoinColumn(name="actID", referencedColumnName="actID", unique=true)}
    )
    private List<ACT> actCollection;

    public Allocation() {
    }

    public Allocation(Integer allocationID) {
        this.allocationID = allocationID;
    }

    public Allocation(Integer allocationID, Date allocationStartDate, Date allocationModDate, Date allocationDueDate, boolean allocationFilled, int templateID) {
        this.allocationID = allocationID;
        this.allocationStartDate = allocationStartDate;
        this.allocationModDate = allocationModDate;
        this.allocationDueDate = allocationDueDate;
        this.allocationFilled = allocationFilled;
        this.templateID = templateID;
    }

    public Integer getAllocationID() {
        return allocationID;
    }

    public void setAllocationID(Integer allocationID) {
        this.allocationID = allocationID;
    }

    public Date getAllocationStartDate() {
        return allocationStartDate;
    }

    public void setAllocationStartDate(Date allocationStartDate) {
        this.allocationStartDate = allocationStartDate;
    }

    public Date getAllocationModDate() {
        return allocationModDate;
    }

    public void setAllocationModDate(Date allocationModDate) {
        this.allocationModDate = allocationModDate;
    }

    public Date getAllocationDueDate() {
        return allocationDueDate;
    }

    public void setAllocationDueDate(Date allocationDueDate) {
        this.allocationDueDate = allocationDueDate;
    }

    public boolean getAllocationFilled() {
        return allocationFilled;
    }

    public void setAllocationFilled(boolean allocationFilled) {
        this.allocationFilled = allocationFilled;
    }

    public CustomerGroup getAllocationCustGroupID() {
        return allocationCustGroupID;
    }

    public void setAllocationCustGroupID(CustomerGroup allocationCustGroupID) {
        this.allocationCustGroupID = allocationCustGroupID;
    }

    public List<ACT> getACTCollection() {
        return actCollection;
    }

    public void setACTCollection(List<ACT> actCollection) {
        this.actCollection = actCollection;
    }

    public int getTemplateID() {
        return templateID;
    }

    public void setTemplateID(int templateID) {
        this.templateID = templateID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (allocationID != null ? allocationID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Allocation)) {
            return false;
        }
        Allocation other = (Allocation) object;
        if ((this.allocationID == null && other.allocationID != null) || (this.allocationID != null && !this.allocationID.equals(other.allocationID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Allocation[ allocationID=" + allocationID + " ]";
    }
    
}
